import { Annotation, MemorySaver, StateGraph } from "@langchain/langgraph";
import { parse, XlsxParseState } from "../node/xlsx";
import { cargo, CargoState } from "../node/format";
import { OutputState } from "../utils/state";

/**
 * 状态
 */
export const GrpahState = Annotation.Root({
  ...XlsxParseState.spec,
  ...CargoState.spec,

  ...OutputState.spec,
});

/**
 * 货物清单
 * @returns
 */
export const graph = () => {
  return new StateGraph(GrpahState)
    .addNode("parse", parse)
    .addNode("cargo", cargo)
    .addEdge("__start__", "parse")
    .addEdge("parse", "cargo")
    .addEdge("cargo", "__end__")
    .compile({
      checkpointer: new MemorySaver(),
    });
};
